
@extends ('layouts/app')

@section('content')
    @csrf
<div class="weui-panel__bd ">
    <a href="/mobile/voucher" >
        <div class="weui-flex  mine">
            <img class="head" src="" alt="">
            <h4 class="weui-flex mine_1">我的</h4>
        </div>
    </a>
</div>
{{--点击钱包触发弹出框--}}
<div class="weui-cells mt-1">
    <a class="weui-cell weui-cell_access" href="/mobile/remaining">
        <div class="weui-cell__hd">
            <svg class="icon icon-2 f40" aria-hidden="true">
                <use xlink:href="#icon-tubiao-12"></use>
            </svg>
        </div>
        <div class="weui-cell__bd">
            <p class="f30">钱包</p>
        </div>
        <div class="weui-cell__ft"></div>
    </a>
    {{--暂时关闭个人中心购物车--}}
    {{--<a class="weui-cell weui-cell_access" href="javascript:;">--}}
        {{--<div class="weui-cell__hd">--}}
            {{--<svg class="icon f28" aria-hidden="true">--}}
                {{--<use xlink:href="#icon-tubiao-9"></use>--}}
            {{--</svg>--}}
        {{--</div>--}}
        {{--<div class="weui-cell__bd">--}}
            {{--<p>购物车</p>--}}
        {{--</div>--}}
        {{--<div class="weui-cell__ft"></div>--}}
    {{--</a>--}}
    <a class="weui-cell weui-cell_access" href="/mobile/order-list">
        <div class="weui-cell__hd">
            <svg class="icon icon-2 f40" aria-hidden="true">
                <use xlink:href="#icon-tubiao-3"></use>
            </svg>
        </div>
        <div class="weui-cell__bd">
            <p class="f30">我的订单</p>
        </div>
        <div class="weui-cell__ft"></div>
    </a>
    <a class="weui-cell weui-cell_access" href="/mobile/Aboutus">
        <div class="weui-cell__hd">
            <svg class="icon icon-2 f40" aria-hidden="true">
                <use xlink:href="#icon-tubiao-3"></use>
            </svg>
        </div>
        <div class="weui-cell__bd">
            <p class="f30">关于我们</p>
        </div>
        <div class="weui-cell__ft"></div>
    </a>
</div>
<div class="weui-cells ">


    <a class="weui-cell weui-cell_access" href="tel:36910000">
        <div class="weui-cell__hd">
            <svg class="icon icon-2 f40" aria-hidden="true">
                <use xlink:href="#icon-tubiao-1"></use>
            </svg>
        </div>
        <div class="weui-cell__bd">
            <p class="f30">联系我们</p>
        </div>
        <div class="weui-cell__ft"></div>
    </a>
    @if(\Illuminate\Support\Facades\Auth::user()->role == '0')
    <a class="weui-cell weui-cell_access inShops" href="javascript:;" onclick="inShops()">
        <div class="weui-cell__hd">
            <svg class="icon icon-2 f40" aria-hidden="true">
                <use xlink:href="#icon-tubiao-1"></use>
            </svg>
        </div>
        <div class="weui-cell__bd">
            <p class="f30">申请成为商家</p>
        </div>
        <div class="weui-cell__ft"></div>
    </a>
    @endif
    @if(\Illuminate\Support\Facades\Auth::user()->role == '1')
    <a class="weui-cell weui-cell_access myShops" href="/mobile/shopAdmin/index">
        <div class="weui-cell__hd">
            <svg class="icon f40" aria-hidden="true">
                <use xlink:href="#icon---"></use>
            </svg>
        </div>
        <div class="weui-cell__bd">
            <p class="f30">我的店铺</p>
        </div>
        <div class="weui-cell__ft"></div>
    </a>
        @endif
</div>
<script>
    //取值_token   input渲染name
    var _token = $("input[name='_token']").val();

    // 获取用户信息
    var userInfo = {};
    getUserInfo(_token, function (res) {
        console.log("res", res);
        //显示用户头像
        userInfo = res;
        showUserInfo(res);
    });
    // 显示用户信息
    function showUserInfo (data) {
        if (data[0].avatar) {
            $(".mine img").attr("src", data[0].avatar);
        } else {
            $(".mine img").attr("src", "/img/eat.png");
        }

        //显示用户名称
        $(".mine .mine_1").text(data[0].name);

        // 显示商家店铺入口
        if (data[0].role > 0) {
            $(".inShops").hide();
            $(".myShops").show();
        } else {
            $(".inShops").show();
            $(".myShops").hide();
        }
    }



    // 申请成为商家
    function inShops () {

        // 判断用户是否已经申请，（在审核）
        console.log("userInfo", userInfo[0].shop_apply);
        if (userInfo[0].shop_apply) {
            $.toast("正在审核中，请耐心等待！", "text");
        } else {
            $.alert("申请成为商家需要1~3个工作日，请耐心等候通知！", function () {
                $.post("/api/user/applyShop", {_token: _token}, function (res) {
                    if (typeof res === 'string') {
                        res = JSON.parse(res);
                    }
                    $.toast(res.info, "text");
                    if (res.code === 200) {
                        getUserInfo(_token, function () {
                            location.reload();
                        });
                    }
                    console.log("res", res);
                });
            });
        }


    }

</script>
@endsection
